Ext.define('CMS.controller.Project', {
    extend:'Ext.app.Controller',

    stores:['ProjectItems'],
    models:['ProjectItem'],

    views:['project.Toolbar', 'project.Tree'],

    refs:[
        {
            ref:'tree',
            selector:'projecttree'
        }
    ],

    init:function () {
        this.control({
            'projecttree':{
                itemdblclick:this.editItem,
                selectionchange:this.selectionChange
            },
            'projecttoolbar #create':{
                click:this.createItem
            }
        });
    },

    createItem:function () {
        var store = this.getProjectItemsStore();
        var newItem = store.create({ id:'www\page1', text:'page 1', leaf:false });
        store.getNodeById('www').appendChild(newItem);
    },

    editItem:function (tree, item) {
        console.log('Double clicked on ' + item.get('id'));
    },

    selectionChange:function (tree, selections) {
        Ext.Array.each(selections, function(item) { console.log('Selected id:' + item.get('id') + ', type:' + item.get('type')); });
    }
});